/*
 *	Simulator package.
 *	CPU
 *	Interrupt controller
 *	I/O devices
 */

#ifndef CPU_H_
#define CPU_H_

#include "interrupt_trap_handler.h"

#ifndef MAX_CYCLE
#define MAX_CYCLE 1000
#endif

#ifndef NO_EVENT
#define NO_EVENT -1
#endif

#ifndef TIMER_QUANTA
#define TIMER_QUANTA 10
#endif

#ifndef EVENT_TOKENS_
#define EVENT_TOKENS_
#define TIMER_INTERRUPT 		0
#define IO_INTERRUPT 			1
#define KEYBOARD_IO_INTERRUPT 	2
#define IO_REQ_TRAP				3
#define MUTEX_LOCK_TRAP			4
#define	MUTEX_UNLOCK_TRAP		5
#define	CONDITION_WAIT_TRAP		6
#define	CONDITION_SIGNAL_TRAP	7
#define START_PROCESS			8
#define STOP_PROCESS			9
#endif

#include "pcb_queue.h"

PCBQueuePtr ready_queue;
PCBQueuePtr waiting_queue;
PCBQueuePtr keyboard_queue;


/*
 *	Prototypes
 */

/*
 *	Starts up the CPU.
 */
int run_cpu(PCBPtr initial[], int proc_count);


/*
 *	Passes the current CPU cycle counter to the interrupt controller.
 *	Returns the index of the process/interrupt to run.  -1 if NO_EVENT.
 */
int call_interrupt_controller(int);

/*
 *	Runs an event (process or interrupt).
 */
int run_event(int, PCBPtr*, int);

/*
 *	Runs the timer.  This will need to be an independent thread.
 *	May not be needed.
 */
int start_timer();

/*
 * Starts a process indicated by the process ID sent.
 */
int start_process(PCBPtr*, int);

/*
 * Stops the process indicated by the ID sent.
 */
int stop_process(PCBPtr*, int);

int (*event_list[10]) (PCBPtr*, int);

#endif

